package com.lebron.kotlin.utils

import android.app.Activity
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.ConnectivityManager
import com.lebron.kotlin.BaseApplication

/**
 * @Author lebron
 * @Date 18-8-1-上午10:40
 * 网络工具类
 */
object NetworkUtils {

    private val connectManager: ConnectivityManager = BaseApplication.instance.applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager

    fun isConnected(): Boolean {

        if (connectManager.activeNetworkInfo.isConnected) {
            return true
        }
        return false
    }
    fun  isWifi():Boolean{
        return connectManager.activeNetworkInfo.type == ConnectivityManager.TYPE_WIFI
    }

    /**
     * 打开网络设置界面
     */
    fun openWifiSetting(activity: Activity) {
        val intent = Intent()
        val cm = ComponentName("com.android.settings",
                "com.android.settings.WirelessSettings")
        intent.component = cm
        intent.action = "android.intent.action.VIEW"
        activity.startActivityForResult(intent, 0)
    }
}